using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace MicroFractal.iTunesBrowser.Core.Data.ITunesDB.Item
{
    public class TrackItem : DataItem
    {

        #region Constructors

        public TrackItem(MemoryStream data)
            : base(data)
        {

            _duration = Helper.ITunesHelper.BytesToInt(data, 40, 4);
            _trackNumber = Helper.ITunesHelper.BytesToInt(data, 44, 4);
            _hasCover = Helper.ITunesHelper.BytesToInt(data, 124, 2) != 0;

            base.Properties = new Dictionary<StringDataTypeEnum, StringData>();
            int len = 0;
            int oldLen = len;
            for (int i = 0; i < base.StringCount; i++)
            {
                oldLen += len;
                len = Helper.ITunesHelper.BytesToInt(data, base.Length + oldLen + 8, 4);
                StringData d = new StringData(Helper.ITunesHelper.GetMemoryStream(data, base.Length + oldLen, len));
                base.Properties.Add(d.StringType, d);
            }

        }

        #endregion

        #region Properties

        private bool _hasCover = false;
        public bool HasCover
        {
            get { return _hasCover; }
        }

        private int _duration;
        /// <summary>
        /// Obtiene o establece la duracion de la cancion en milisegundos.
        /// </summary>
        public int Duration
        {
            get { return _duration; }
            set { _duration = value; }
        }

        private int _trackNumber;
        /// <summary>
        /// Obtiene o establece el numero del track en el album.
        /// </summary>
        public int TrackNumber
        {
            get { return _trackNumber; }
            set { _trackNumber = value; }
        }


        #endregion
    }
}
